﻿using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
using WorkFlowCore.Conditions;
using WorkFlowCore.EventHandlers;
using WorkFlowCore.IRepositories;
using WorkFlowCore.UserSelectors;
using WorkFlowCore.Workflows;
using WorkFlowCore.WorkTasks;

namespace WorkFlowCore
{
    public static class WorkFlowCoreService
    {
        public class WorkFlowCoreServiceConfig
        {
            public void RegisterSelector(params Assembly[] assemblies)
            {
                UserSelectorManager.RegisterSelector(assemblies);
            }
            public void Registercondition(params Assembly[] assemblies)
            {
                ConditionManager.Registercondition(assemblies);
            }
            public void RegisterSubscriptions(params Assembly[] assemblies)
            {
                EventManager.RegisterSubscriptions(assemblies);
            }
        }
        public static void AddWorkFlowCore(this IServiceCollection services,Action<WorkFlowCoreServiceConfig> config=null)
        {
            services.AddScoped<UserSelectorManager>();
            services.AddScoped<ConditionManager>();
            services.AddScoped<EventManager>();

            services.AddScoped<Workflow>();
            services.AddScoped<WorkflowVersion>();
            services.AddScoped<WorkflowNode>();
            services.AddScoped<WorkflowLine>();
            services.AddScoped<WorkTask>();
            services.AddScoped<WorkStep>();
            services.AddScoped<WorkflowManager>();

            config?.Invoke(new WorkFlowCoreServiceConfig());
        }
    }
}
